//
//  UIButton+Extension.swift
//  Lease_IOS
//
//  Created by Mr.wang on 2018/5/11.
//  Copyright © 2018年 Mr.Wang. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa

extension UIButton {
    
    class func navigationItemButton(title: String) -> UIButton {
        let button = UIButton()
        button.setTitle(title, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.black, for: .normal)
        button.sizeToFit()
        return button
    }
}

class RoundRectButton: UIButton {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setTitleColor(UIColor.white, for: .normal)
        self.setBackgroundImage(UIImage.imageWithColor(APPConfig.baseColor), for: .normal)
        self.setBackgroundImage(UIImage.imageWithColor(#colorLiteral(red: 0.8, green: 0.8, blue: 0.8, alpha: 1)), for: .disabled)
        self.clipsToBounds = true
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        layer.cornerRadius = height * 0.5
    }
    
}

class LeftTitleButton: UIButton {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0 - (self.imageView?.width ?? 0) - 2, bottom: 0, right: (self.imageView?.width ?? 0) + 2)
        self.imageEdgeInsets = UIEdgeInsets(top: 0, left: (self.titleLabel?.width ?? 0) + 2, bottom: 0, right: 0 - (self.titleLabel?.width ?? 0) - 2)
    }
    
}
